package com.bete.otherutils;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import me.jessyan.autosize.utils.LogUtils;

public class MainActivity extends BaseActivity {
    @Override
    protected void initData(Bundle savedInstanceState) {
        Button btn_update = findViewById(R.id.btn_update);
        Button btn_soft_download = findViewById(R.id.btn_soft_download);
        Button btn_soft_update = findViewById(R.id.btn_soft_update);
        btn_soft_download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.bete.updata", "com.bete.updata.DownLoadActivity"));
                intent.putExtra("download_path", "http://192.168.1.114:7070/temp.apk");
                intent.putExtra("save_download_path", "/sdcard/updataapk/");
                intent.putExtra("download_path_ending", "apk");
                startActivity(intent);
            }
        });

        btn_soft_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.bete.updata", "com.bete.updata.UpLoadDataActivity"));
                intent.putExtra("upload_url", "http://192.168.1.114:7070/lamp-web/MutilUploadServlet");
                intent.putExtra("upload_path", "/1/log/");
                intent.putExtra("updateFilePath", "/sdcard/updataapk/1.txt");
                intent.putExtra("packageName", getPackageName());
                startActivity(intent);
            }
        });

        btn_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                update();
            }
        });
    }

    @Override
    protected int getLayoutID() {
        return R.layout.activity_main;
    }

    public void update() {
        Intent intent = new Intent();
//        String targetfile = Canstant.SD_CARD + "screenshot.png";
//        ScreenShotUtil.screenShots(view, targetfile);
        intent.setComponent(new ComponentName("com.bete.updata", "com.bete.updata.UpdataActivity"));
        // /sdcard/updataapk/debug_v1.0.14.31_debug_240816.apk
//        intent.putExtra("apkFilePath", "/sdcard/updateapk/debug_v1.0.14.31_debug_240816.apk");
//        intent.putExtra("apkFilePath", "/sdcard/updataapk/debug_v1.0.14.31_debug_240816.apk");
        intent.putExtra("apkFilePath", "/sdcard/updataapk/test.apk");
//        intent.putExtra("apkFilePath", apkFilePath);
//        intent.putExtra("httpapkUrl", "http://192.168.139.1:8080/test.apk");
//        intent.putExtra("packageName", getPackageName());
        intent.putExtra("packageName", getPackageName());
//        intent.putExtra("is_net_work_download_file", false);
//        intent.putExtra("time_out_time", 6000);
//        intent.putExtra("software_screenshots_path", targetfile);
        startActivityForResult(intent, 0x0002);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x0002 && resultCode == RESULT_OK) {
            String errormsg = data.getStringExtra("errormsg");
            LogUtils.e(" errormsg value is : " + errormsg);
        }

    }
}
